<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	<style type="text/css">
    .errorText
    {
        color:red;
    }
    </style>
</head>
<body>
	<form id="form1" method="post">
	<input name="id" class="mini-hidden" />
        <div style="padding-left:50px;padding-bottom:15px;padding-top: 25px;">
            <table style="width: 100%" cellspacing="5px">
               	<tr>
            		<td>类型：</td>
                    <td>
                    	<input id="type" name="type" required="true" emptyText="请选择..."  class="mini-combobox" url="dictionary_cm_key_val_view.do?typeName=SMS_PHRASE_TYPE" valueField="keyName" textField="keyValue" style="width: 200px"/>
                    </td>
                    <td id="cycle_error" class="errorText" ></td>
                </tr>
                <tr>
            		<td>内容：</td>
                    <td>
                        <input name="content" emptyText="请输入内容" errorMode="none" onvalidation="validation" requiredErrorText="请输入短信内容" 
                        required="true"  class="mini-textarea" vtype="maxLength:70" style="width:290px;height: 160px" />
                    </td>
                    <td id="content_error" class="errorText" ></td>
                </tr>
            </table>
        </div>
        <div style="text-align:center;padding-top:20px;">
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:50px;">确定</a>       
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
        </div>        
    </form>

<script type="text/javascript">
	mini.parse();
	var form = new mini.Form("form1");
	//保存数据
	function SaveData() {
	    var o = form.getData(true); 
	    form.validate();
	    if (form.isValid() == false) return;
	    $.ajax({
	        url: "sms_phrase_save_add.do",
			type: 'post',
			dataType: 'json',
	        data: o,
	        cache: false,
	        success: function (text) {
	            if(text.success){
	            	window.CloseOwnerWindow("succ");
	            }else{
	            	mini.alert("数据错误");
	            }
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	            alert(jqXHR.responseText);
	            window.CloseOwnerWindow();
	        }
	    });
	}
	
    function CloseWindow(action) {            
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();            
    }
    
    function onOk(e) {
        SaveData();
    }
    
    function onCancel(e) {
        CloseWindow("cancel");
    }
    
    //验证
    function validation(e) {
    	 var id =e.sender.name + "_error";
         var el = document.getElementById(id);
         checkValidation(e);
    }
    
    function updateError(e) {
        var id =e.sender.name + "_error";
        var el = document.getElementById(id);
        if (el) {
            el.innerHTML =e.errorText;
        }
    }
    
    function checkValidation(e) {
        updateError(e);
    }
</script>
</body>
</html>